﻿using MES.Server.AuthServer.Utility.JwtService;
using MES.Server.Common;
using MES.Server.Entities;
using MES.Server.EntitiesDTO;
using MES.Server.IService;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using SqlSugar;

namespace MES.Server.AuthServer
{
    /// <summary>
    /// 专属用于登录的，颁发Token
    /// </summary>
    public static class AccountApiExt
    {
        public static void LoginApi(this WebApplication app)
        {
            //JWT： 对称加密解密的 token  非对称的加解密token
            //登录，颁发Token
            app.MapPost("auth/Account",async ([FromServices] CustomJWTService _iJWTService, UserEntity user) =>
            {
                string accessToken = _iJWTService.CreateToken(user, out string refreshtoken);
               
                return await Task.FromResult(new ApiDataResult<object>()
                {
                    Success = true,
                    Message = "登录成功",
                    Data = accessToken
                });
            });
        }
    }
}
